package com.googlecode.bip.util;

import java.io.Serializable;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import com.googlecode.bip.entity.Roles;

/**
 * Helper to identify roles
 *
 * @author Claude CHOISNET
 */
public class RolesIdentifier implements Serializable
{
    private static final long serialVersionUID = 1L;
    private Set<Roles> roles;

    public RolesIdentifier( final Set<Roles> roles )
    {
        this.roles = roles;
    }

    public boolean isUser()
    {
        return this.roles.contains( Roles.BIP_USER );
    }

    public boolean isReferent()
    {
        return this.roles.contains( Roles.BIP_REF );
    }

    public boolean isAuthor()
    {
        return this.roles.contains( Roles.BIP_AUTHOR );
    }

    public boolean _isAdministrator()
    {
        return this.roles.contains( Roles.BIP_ADMIN );
    }

    public static boolean isUser(
            final HttpServletRequest request
            )
    {
        return request.isUserInRole( Roles.BIP_USER.name() );
    }

   public static boolean isReferent(
           final HttpServletRequest request
           )
   {
       return request.isUserInRole( Roles.BIP_REF.name() );
   }

   public static boolean isAuthor(
        final HttpServletRequest request
        )
    {
        return request.isUserInRole( Roles.BIP_AUTHOR.name() );
    }

    public static boolean _isAdministrator(
            final HttpServletRequest request
            )
    {
        return request.isUserInRole( Roles.BIP_ADMIN.name() );
    }
}
